package com.dyb.recuitment.controller;


import com.dyb.recuitment.common.Result;
import com.dyb.recuitment.entity.CompanyIndustry;
import com.dyb.recuitment.entity.UserLog;
import com.dyb.recuitment.service.ICompanyIndustryService;
import com.dyb.recuitment.service.IUserLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 行业领域表 前端控制器
 * </p>
 *
 * @author 邓宇斌
 * @since 2022-02-23
 */
@RestController
@Api(tags = "行业领域管理(CompanyIndustry)")
@RequestMapping("/company_industry")
public class CompanyIndustryController {

    @Autowired
    private ICompanyIndustryService companyIndustryService;

    @Autowired
    private IUserLogService userLogService;

    @ApiOperation(value = "添加行业领域", notes = "通过标题和备注添加行业领域" + "{\"title\":\"\",\"remark\":\"\"}")
    @ApiImplicitParam(name = "companyIndustry", value = "CompanyIndustry类")
    @PostMapping("/add")
    public Object add(@RequestBody CompanyIndustry companyIndustry) {
        Object data = null;
        try {
            data = companyIndustryService.add(companyIndustry);
//            userLogService.add(new UserLog(1, "添加行业领域"));
            if (data == null || (int) data == 0) {
                return Result.failure(data, "添加失败!");
            }
            return Result.success(data, "添加成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "行业领域详情", notes = "通过ID查询行业领域详情 {\"id\":1}")
    @ApiImplicitParam(name = "companyIndustry", value = "CompanyIndustry类")
    @PostMapping("/selectById")
    public Object selectById(@RequestBody CompanyIndustry companyIndustry) {
        Object data = null;
        try {
            data = companyIndustryService.getById(companyIndustry);
            if (data == null) {
                return Result.warning(data, "行业领域为空!");
            }
            return Result.success(data, "查询成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "修改行业领域", notes = "修改行业领域 {\"\":\"\",\"id\":1}")
    @ApiImplicitParam(name = "companyIndustry", value = "CompanyIndustry类")
    @PostMapping("/update")
    public Object update(@RequestBody CompanyIndustry companyIndustry) {
        Object data = null;
        try {
            data = companyIndustryService.update(companyIndustry);
            if (data == null || data == (Integer) 0) {
                return Result.failure(data, "修改失败!");
            }
            return Result.success(data, "修改成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "删除行业领域", notes = "通过ID删除行业领域" + "{\"id\":1}")
    @ApiImplicitParam(name = "companyIndustry", value = "CompanyIndustry类")
    @PostMapping("/delete")
    public Object delete(@RequestBody CompanyIndustry companyIndustry) {
        Object data = null;
        try {
            data = companyIndustryService.delete(companyIndustry);
//            userLogService.add(new UserLog(resume.getUserId(), "删除行业领域"));
            if (data == null || data == (Integer) 0) {
                return Result.failure(data, "删除失败!");
            }
            return Result.success(data, "删除成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "按条件查询行业领域", notes = "按条件查询行业领域 {\"title\":\"\"}")
    @ApiImplicitParam(name = "companyIndustry", value = "CompanyIndustry类")
    @PostMapping("/selectByCompanyIndustry")
    public Object selectByCompanyIndustry(@RequestBody CompanyIndustry companyIndustry) {
        Object data = null;
        try {
            data = companyIndustryService.selectByCompanyIndustry(companyIndustry);
            if (data == null || ((List) data).size() <= 0) {
                return Result.warning(data, "暂无行业领域!");
            }
            return Result.success(data, "查询成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

    @ApiOperation(value = "查询所有行业领域", notes = "查询所有行业领域")
    @GetMapping("/selectAllCompanyIndustry")
    public Object selectAllCompanyIndustry() {
        Object data = null;
        try {
            data = companyIndustryService.selectAllCompanyIndustry();
            if (data == null || ((List) data).size() <= 0) {
                return Result.warning(data, "暂无行业领域!");
            }
            return Result.success(data, "查询成功!");
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return Result.failure(data);
    }

}
